package com.sikadwafastdaisfondturbo.pretloan.utils.helper

import java.math.BigDecimal
import java.math.RoundingMode


/**
 * 权限 + 进件信息 额度/通过率 提升处理逻辑
 */
object SikadwaAmountPlusHelper {

    /**
     * 权限页 提升额度显示固定为： 外显额度 * 10%
     */
    fun takeSikadwaGuideStepPermissionLoanAmount(showAmount: String): Float{
        return BigDecimal(showAmount).multiply(BigDecimal("0.1")).stripTrailingZeros().toPlainString().toFloat()
    }

    /**
     * 权限页 提升通过率(pass rate)显示固定为： 10%
     */
    fun takeSikadwaGuideStepPermissionPassRate(): Float{
        return 10f
    }

    /**
     * 进件信息提升额度值
     *     = 外显额度 * 30% + (已完成步数 * (60% / 进件环节总数) * 外显额度)
     */
    fun takeSikadwaGuideStepProcessLoanAmount(showAmount: String): Float{
        //总步骤
        val allStepLength = SikadwaMainProcessHelper.takeSikadwaMainProcessAllStepTitleList().size
        //剩余步骤
        val stepLength = SikadwaMainProcessHelper.takeSikadwaMainProcessStepList().size
        //已完成流程步数
        val completeNum = allStepLength - stepLength

        //权限页增加的额度
        val addPerAmount = BigDecimal(showAmount).multiply(BigDecimal("0.3")).stripTrailingZeros().toPlainString()
        //已完成的进件步骤增加的额度
        val addStepAmount = BigDecimal(completeNum.toString()).multiply(BigDecimal("0.6").divide(BigDecimal(allStepLength.toString()),2, RoundingMode.DOWN)).multiply(BigDecimal(showAmount)).stripTrailingZeros().toPlainString()

        return BigDecimal(addPerAmount).add(BigDecimal(addStepAmount)).stripTrailingZeros().toPlainString().toFloat()
    }

    /**
     * 进件信息提升通过率
     *     = 30% + (已完成步数 * (60% / 进件环节总数))
     */
    fun takeSikadwaGuideStepProcessPassRate(): Float{
        //总步骤
        val allStepLength = SikadwaMainProcessHelper.takeSikadwaMainProcessAllStepTitleList().size
        //剩余步骤
        val stepLength = SikadwaMainProcessHelper.takeSikadwaMainProcessStepList().size
        //已完成流程步数
        val completeNum = allStepLength - stepLength

        //权限页增加的额度
        val addPerPassRate = "30"
        //已完成的进件步骤增加的额度
        val addStepPassRate = BigDecimal(completeNum.toString()).multiply(BigDecimal("60").divide(BigDecimal(allStepLength.toString()),2, RoundingMode.DOWN)).stripTrailingZeros().toPlainString()

        return BigDecimal(addPerPassRate).add(BigDecimal(addStepPassRate)).stripTrailingZeros().toPlainString().toFloat()
    }
}